﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using Infragistics.Win.UltraWinGrid;
using WHC.OrderWater.Commons;
using WHC.Pager.Entity;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using Maticsoft.DBUtility;

namespace CKNetFrameWork
{
    public partial class Frm_ConsultReg : DockContent
    {
        private TrainingDB.BLL.CK_StudentInfo m_bllCK_StudentInfo = new TrainingDB.BLL.CK_StudentInfo();
        private TrainingDB.BLL.CK_StudentRefer m_bllCK_StudentRefer = new TrainingDB.BLL.CK_StudentRefer();
        private TrainingDB.BLL.CK_SchoolTab m_bllCK_SchoolTab = new TrainingDB.BLL.CK_SchoolTab();
        private TrainingDB.BLL.CK_InfoFromTab m_bllCK_InfoFromTab = new TrainingDB.BLL.CK_InfoFromTab();
        private TrainingDB.BLL.CK_IntentionDegreeTab m_bllCK_IntentionDegreeTab = new TrainingDB.BLL.CK_IntentionDegreeTab();
        private TrainingDB.BLL.T_ACL_User m_bllT_ACL_User = new TrainingDB.BLL.T_ACL_User();
        private TrainingDB.BLL.CK_StudentReferDetail m_bllCK_StudentReferDetail = new TrainingDB.BLL.CK_StudentReferDetail();
        private TrainingDB.BLL.CK_ConsultWayTab m_bllCK_ConsultWayTab = new TrainingDB.BLL.CK_ConsultWayTab();
        private TrainingDB.BLL.CK_ClassTab m_bllCK_ClassTab = new TrainingDB.BLL.CK_ClassTab();
        private int m_nStudentReferID = -1;
        private int m_nDelIndex = -1;
        private int m_nDelIndex2 = -1;
        private bool m_bInsertFlag = false;
        private bool m_bInsertFlag2 = false;
        private Dictionary<string, string> m_dicColName2AliasName = new Dictionary<string, string>();
        private Dictionary<string, string> m_dicColAliasName2Name = new Dictionary<string, string>();
        private string m_filter = "";

        public Frm_ConsultReg()
        {
            InitializeComponent();
        }


        private void ShowAllRecordInDataGridView(string strWhere)
        {
            BindData(strWhere);
        }

        private void SearchResult()
        {
            this.pager1.CurrentPageIndex = 1;
            m_filter = "";
            int nIndex = this.ultraGrid1.ActiveRow.Index;
            List<object> lstO = this.ultraGrid1.DisplayLayout.Bands[0].ColumnFilters.All.ToList();

            string strColumnName;
            string strColumnValue;
            SearchCondition condition = new SearchCondition();
            foreach (object o in lstO)
            {
                ColumnFilter cf = (ColumnFilter)o;
                strColumnName = cf.Column.Key;
                strColumnValue = cf.FilterConditions.Count > 0 ? ((FilterCondition)cf.FilterConditions.All[0]).CompareValue.ToString() : "";
                if (strColumnValue != "")
                {
                    condition = condition.AddCondition(m_dicColAliasName2Name[strColumnName], strColumnValue, SqlOperator.Equal);
                }
            }

            m_filter = condition.BuildConditionSql();
            m_filter = m_filter.Replace("Where", "");
            ShowAllRecordInDataGridView(m_filter);
        }
        private void AddNewRow()
        {
            if (Frm_Main.CheckPerm(this.Text, "增加"))
            {
                UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
            }
            else
            {
                MessageBox.Show("对不起您没有该权限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }
        private void ultraGrid1_KeyDown_1(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SearchResult();
            }
          
            if (e.KeyCode == Keys.Enter && e.Modifiers == Keys.Control)
            {

                if (!m_bInsertFlag)
                {
                    AddNewRow();
                    //UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
                    //  row.Cells[2] = DateTime.Parse("1900-01-01");
                }
            }
            switch (e.KeyCode)
            {

                case Keys.Up:
                    {
                        string strTemp = this.ultraGrid1.ActiveCell.Column.Header.Caption;

                        int nColumnIndex = this.ultraGrid1.ActiveCell.Column.Index;
                        int nIndex = ultraGrid1.ActiveRow.Index;
                        if (nIndex > 0)
                            nIndex--;
                        this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid1.PerformAction(UltraGridAction.AboveCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Down:
                    {
                        string strTemp = this.ultraGrid1.ActiveCell.Column.Header.Caption;

                        int nColumnIndex = this.ultraGrid1.ActiveCell.Column.Index;
                        int nIndex = ultraGrid1.ActiveRow.Index;
                        if (nIndex < ultraGrid1.Rows.Count - 1)
                            nIndex++;
                        this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid1.PerformAction(UltraGridAction.BelowCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Right:
                    this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid1.PerformAction(UltraGridAction.NextCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
                case Keys.Left:
                    this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid1.PerformAction(UltraGridAction.PrevCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
            }

        }
        private bool AddGoodsDetail(int nRowIndex)
        {

            try
            {
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[nRowIndex];

                TrainingDB.Model.CK_StudentRefer modelCK_StudentRefer = new TrainingDB.Model.CK_StudentRefer();

                modelCK_StudentRefer.CK_SchoolTabID = Convert.ToInt32(CurrentUGR.Cells["校区名称"].Value.ToString(), 10);
                modelCK_StudentRefer.CK_OperUserID = Frm_Main.m_nLoginUserId;
                modelCK_StudentRefer.CK_InfoFromTabID = Convert.ToInt32(CurrentUGR.Cells["信息来源"].Value.ToString());
                modelCK_StudentRefer.CK_ConsultPersonID = Convert.ToInt32(CurrentUGR.Cells["咨询师"].Value.ToString());
                modelCK_StudentRefer.CK_IntentionDegreeTabID = Convert.ToInt32(CurrentUGR.Cells["意向程度"].Value.ToString());

                modelCK_StudentRefer.referDate = (DateTime)CurrentUGR.Cells["登记日期"].Value;
                modelCK_StudentRefer.stdtName = CurrentUGR.Cells["学员姓名"].Value.ToString();
                modelCK_StudentRefer.sex = CurrentUGR.Cells["性别"].Value.ToString();
                modelCK_StudentRefer.education = CurrentUGR.Cells["文化程度"].Value.ToString();
                modelCK_StudentRefer.currSchool = CurrentUGR.Cells["所在学校"].Value.ToString();
                modelCK_StudentRefer.grade = CurrentUGR.Cells["年级"].Value.ToString();

                modelCK_StudentRefer.mobile = CurrentUGR.Cells["本人手机"].Value.ToString();
                modelCK_StudentRefer.tel = CurrentUGR.Cells["固定电话"].Value.ToString();
                modelCK_StudentRefer.linkAddr = CurrentUGR.Cells["联系地址"].Value.ToString();
                modelCK_StudentRefer.postcode = CurrentUGR.Cells["邮编"].Value.ToString();
                modelCK_StudentRefer.eMail = CurrentUGR.Cells["电子邮件"].Value.ToString();
                modelCK_StudentRefer.qqMsn = CurrentUGR.Cells["QQ/MSN"].Value.ToString();
                modelCK_StudentRefer.motherName = CurrentUGR.Cells["家长姓名"].Value.ToString();
                modelCK_StudentRefer.motherMobile = CurrentUGR.Cells["家长手机"].Value.ToString();
                modelCK_StudentRefer.motherTel = CurrentUGR.Cells["家长固话"].Value.ToString();
                modelCK_StudentRefer.motherWorkUnit = CurrentUGR.Cells["家长单位"].Value.ToString();
                modelCK_StudentRefer.referMemo = CurrentUGR.Cells["备注"].Value.ToString();
                modelCK_StudentRefer.nextRvstDate = (DateTime)CurrentUGR.Cells["下次联系日期"].Value;
                modelCK_StudentRefer.birthday = (DateTime)CurrentUGR.Cells["生日"].Value;


                int nId = m_bllCK_StudentRefer.Add(modelCK_StudentRefer);
                this.pager1.CurrentPageIndex = 1;
                ShowAllRecordInDataGridView("CK_StudentReferid = '" + nId.ToString() + "'");
      //          MessageBox.Show("添加教室成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }
        private void InitNewAddRowValue(int nIndex)
        {
            UltraGridRow CurrentUGR = ultraGrid1.Rows[nIndex];

            CurrentUGR.Cells["校区名称"].Value = 1;
            CurrentUGR.Cells["信息来源"].Value = 1;
            CurrentUGR.Cells["咨询师"].Value = 1;
            CurrentUGR.Cells["意向程度"].Value = 1;
            CurrentUGR.Cells["登记日期"].Value = System.DateTime.Now.Date;
            CurrentUGR.Cells["下次联系日期"].Value = System.DateTime.Now.Date;
            CurrentUGR.Cells["生日"].Value = System.DateTime.Now.Date;
            CurrentUGR.Cells["学员姓名"].Value = "";
            CurrentUGR.Cells["性别"].Value = "";
            CurrentUGR.Cells["文化程度"].Value = "";
            CurrentUGR.Cells["所在学校"].Value = "";
            CurrentUGR.Cells["年级"].Value = "";
            CurrentUGR.Cells["本人手机"].Value = "";
            CurrentUGR.Cells["固定电话"].Value = "";
            CurrentUGR.Cells["联系地址"].Value = "";
            CurrentUGR.Cells["邮编"].Value = "";
            CurrentUGR.Cells["电子邮件"].Value = "";
            CurrentUGR.Cells["QQ/MSN"].Value = "";
            CurrentUGR.Cells["家长姓名"].Value = "";
            CurrentUGR.Cells["家长手机"].Value = "";
            CurrentUGR.Cells["家长固话"].Value = "";
            CurrentUGR.Cells["家长单位"].Value = "";
            CurrentUGR.Cells["备注"].Value = "";


            if (m_bInsertFlag)
            {
                ultraGrid1.Rows[nIndex].Cells[0].Activation = Activation.ActivateOnly;
                m_bInsertFlag = false;
                AddGoodsDetail(nIndex);

            }

        }

        private void ultraGrid1_AfterRowInsert_1(object sender, RowEventArgs e)
        {
            ultraGrid1.Rows[e.Row.Index].Cells[1].IgnoreRowColActivation = true;
            ultraGrid1.Rows[e.Row.Index].Cells[1].Activation = Activation.AllowEdit;
            ultraGrid1.Rows[e.Row.Index].Cells[1].Activate();
            ultraGrid1.PerformAction(UltraGridAction.EnterEditMode);
            m_bInsertFlag = true;
            InitNewAddRowValue(e.Row.Index);
        }

        private bool ModifyGoodsDetail(int nRowIndex)
        {

            try
            {
                if (!Frm_Main.CheckPerm(this.Text, "修改"))
                {
                    MessageBox.Show("对不起您没有该权限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[nRowIndex];
                int nSelectFinRecvMoneyDetailTab_NewID = Convert.ToInt32(CurrentUGR.Cells[0].Value.ToString(), 10);
                TrainingDB.Model.CK_StudentRefer modelCK_StudentRefer = m_bllCK_StudentRefer.GetModel(nSelectFinRecvMoneyDetailTab_NewID);

                modelCK_StudentRefer.CK_OperUserID = Frm_Main.m_nLoginUserId;

                modelCK_StudentRefer.referDate = (DateTime)CurrentUGR.Cells["登记日期"].Value;
                modelCK_StudentRefer.stdtName = CurrentUGR.Cells["学员姓名"].Value.ToString();
                modelCK_StudentRefer.sex = CurrentUGR.Cells["性别"].Value.ToString();
                modelCK_StudentRefer.education = CurrentUGR.Cells["文化程度"].Value.ToString();
                modelCK_StudentRefer.currSchool = CurrentUGR.Cells["所在学校"].Value.ToString();
                modelCK_StudentRefer.grade = CurrentUGR.Cells["年级"].Value.ToString();

                modelCK_StudentRefer.mobile = CurrentUGR.Cells["本人手机"].Value.ToString();
                modelCK_StudentRefer.tel = CurrentUGR.Cells["固定电话"].Value.ToString();
                modelCK_StudentRefer.linkAddr = CurrentUGR.Cells["联系地址"].Value.ToString();
                modelCK_StudentRefer.postcode = CurrentUGR.Cells["邮编"].Value.ToString();
                modelCK_StudentRefer.eMail = CurrentUGR.Cells["电子邮件"].Value.ToString();
                modelCK_StudentRefer.qqMsn = CurrentUGR.Cells["QQ/MSN"].Value.ToString();
                modelCK_StudentRefer.motherName = CurrentUGR.Cells["家长姓名"].Value.ToString();
                modelCK_StudentRefer.motherMobile = CurrentUGR.Cells["家长手机"].Value.ToString();
                modelCK_StudentRefer.motherTel = CurrentUGR.Cells["家长固话"].Value.ToString();
                modelCK_StudentRefer.motherWorkUnit = CurrentUGR.Cells["家长单位"].Value.ToString();
                modelCK_StudentRefer.referMemo = CurrentUGR.Cells["备注"].Value.ToString();
                modelCK_StudentRefer.nextRvstDate = (DateTime)CurrentUGR.Cells["下次联系日期"].Value;
                modelCK_StudentRefer.birthday = (DateTime)CurrentUGR.Cells["生日"].Value;


                string strBGH = CurrentUGR.Cells["校区名称"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_StudentRefer.CK_SchoolTabID = Convert.ToInt32(CurrentUGR.Cells["校区名称"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_SchoolTab.GetList("CK_SchoolTabName = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_StudentRefer.CK_SchoolTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_SchoolTabID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["信息来源"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_StudentRefer.CK_InfoFromTabID = Convert.ToInt32(CurrentUGR.Cells["信息来源"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_InfoFromTab.GetList("CK_InfoFromName = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_StudentRefer.CK_InfoFromTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_InfoFromTabID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["咨询师"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_StudentRefer.CK_ConsultPersonID = Convert.ToInt32(CurrentUGR.Cells["咨询师"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllT_ACL_User.GetList("Name = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_StudentRefer.CK_ConsultPersonID = Convert.ToInt32(ds.Tables[0].Rows[0]["ID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["意向程度"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_StudentRefer.CK_IntentionDegreeTabID = Convert.ToInt32(CurrentUGR.Cells["意向程度"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_IntentionDegreeTab.GetList("CK_IntentionDegreeName = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_StudentRefer.CK_IntentionDegreeTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_IntentionDegreeTabID"].ToString(), 10);
                    }
                }

                m_bllCK_StudentRefer.Update(modelCK_StudentRefer);

               // MessageBox.Show("修改教室成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }

        private void ultraGrid1_AfterCellActivate_1(object sender, EventArgs e)
        {
            try
            {
                int iIndex = this.ultraGrid1.ActiveCell.Row.Index;
                if (iIndex < 0)
                    return;
                m_nDelIndex = ultraGrid1.ActiveRow.Index;
                UltraGridRow CurrentUGR = ultraGrid1.Rows[m_nDelIndex];
                m_nStudentReferID = Convert.ToInt32(ultraGrid1.ActiveRow.Cells["CK_StudentReferID"].Value.ToString());

                ShowAllMXRecordInDataGridView("CK_StudentReferID = '" + m_nStudentReferID + "'");
            }
            catch (Exception ex)
            {

            }

        }

        private void ultraGrid1_BeforeRowUpdate_1(object sender, CancelableRowEventArgs e)
        {
            try
            {
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[e.Row.Index];

                if (m_bInsertFlag)
                {
                    ultraGrid1.Rows[e.Row.Index].Cells[2].Activation = Activation.ActivateOnly;
                    m_bInsertFlag = false;
                    if (!AddGoodsDetail(e.Row.Index))
                        e.Cancel = true;
                }
                else//修改
                {

                    ModifyGoodsDetail(e.Row.Index);

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;
            }
        }

        private void ultraGrid1_BeforeRowsDeleted_1(object sender, BeforeRowsDeletedEventArgs e)
        {
            e.DisplayPromptMsg = false;
            if (!m_bInsertFlag)
            {
                int nSelectFinRecvMoneyDetailTab_NewID = Convert.ToInt32(ultraGrid1.ActiveRow.Cells[0].Value.ToString(), 10);
                TrainingDB.Model.CK_StudentRefer modelCK_StudentReferOld = m_bllCK_StudentRefer.GetModel(nSelectFinRecvMoneyDetailTab_NewID);

                if (modelCK_StudentReferOld == null)
                {
                    MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (MessageBox.Show("确实要删除该条记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    try
                    {

                        m_bllCK_StudentRefer.Delete(nSelectFinRecvMoneyDetailTab_NewID);



                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        e.Cancel = true;
                    }
                }
                else
                {
                    e.Cancel = true;
                }
            }
            else
            {
                MessageBox.Show("插入未完成，不能删除记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;
            }
        }

    

        public string SqlValueList(string sql)
        {
            DataSet ds = DbHelperSQL.Query(sql.ToString());
            string strTotal = ds.Tables[0].Rows[0]["Total"].ToString();

            return strTotal;
        }

        /// <summary>    
        /// 执行SQL查询语句，返回所有记录的DataTable集合。    
        /// </summary>    
        /// <param name="sql">SQL查询语句</param>    
        /// <returns></returns>    
        public DataTable SqlTable(string sql)
        {
            DataSet ds = DbHelperSQL.Query(sql.ToString());
            return ds.Tables[0];
        }


        private DataTable FindToDataTable(string where, PagerInfo pagerInfo)
        {
            WHC.Pager.WinControl.PagerHelper helper = new WHC.Pager.WinControl.PagerHelper(@"select 
CK_StudentReferID
,CK_SchoolTab.CK_SchoolTabName
,CK_InfoFromTab.CK_InfoFromName
,CK_IntentionDegreeTab.CK_IntentionDegreeName
,T_ACL_User.Name
,t2.Name tName
,referDate
,stdtName
--,referPYHC
,sex
,education
,currSchool 
,grade
,mobile
,tel 
,linkAddr
,postcode
,CK_StudentRefer.eMail 
,CK_StudentRefer.qqMsn
,motherName
,motherMobile 
,motherTel
,motherWorkUnit
,nextRvstDate
,CK_StudentRefer.referMemo
,CK_StudentRefer.birthday
from CK_StudentRefer
 join CK_SchoolTab on CK_SchoolTab.CK_SchoolTabid = CK_StudentRefer.CK_SchoolTabid 
 join CK_InfoFromTab on CK_InfoFromTab.CK_InfoFromTabID = CK_StudentRefer.CK_InfoFromTabID
 join T_ACL_User on T_ACL_User.ID = CK_StudentRefer.CK_ConsultPersonID
 join T_ACL_User t2 on t2.ID = CK_StudentRefer.CK_OperUserID
 join CK_IntentionDegreeTab on CK_IntentionDegreeTab.CK_IntentionDegreeTabID = CK_StudentRefer.CK_IntentionDegreeTabID
", "*", "CK_StudentReferID", pagerInfo.PageSize, pagerInfo.CurrenetPageIndex, true, where);
            string countSql = helper.GetPagingSql(WHC.Pager.WinControl.DatabaseType.SqlServer, true);
            string dataSql = helper.GetPagingSql(WHC.Pager.WinControl.DatabaseType.SqlServer, false);

            string value = SqlValueList(countSql);
            pagerInfo.RecordCount = Convert.ToInt32(value);//为了显示具体的信息，需要设置总记录数
            DataTable dt = SqlTable(dataSql);
            this.pager1.InitPageInfo(pagerInfo.RecordCount, pagerInfo.PageSize);
            return dt;
        }

        private void BindData(string strWhere)
        {
            this.ultraGrid1.DataSource = null;
            DataTable dt = FindToDataTable(strWhere, this.pager1.PagerInfo);

            DataSet dsTemp = m_bllCK_SchoolTab.GetOnlyList("");

            this.ultraDropDownDep.DataSource = dsTemp.Tables[0];
            this.ultraDropDownDep.DisplayMember = "校区名称";
            this.ultraDropDownDep.ValueMember = "CK_SchoolTabID";
            this.ultraDropDownDep.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownDep.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownDep.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownDep.DisplayLayout.Bands[0].Columns["校区名称"].Hidden = false;


            dsTemp = m_bllCK_InfoFromTab.GetList("");

            this.ultraDropDownInfoFrom.DataSource = dsTemp.Tables[0];
            this.ultraDropDownInfoFrom.DisplayMember = "CK_InfoFromName";
            this.ultraDropDownInfoFrom.ValueMember = "CK_InfoFromTabID";
            this.ultraDropDownInfoFrom.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownInfoFrom.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownInfoFrom.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownInfoFrom.DisplayLayout.Bands[0].Columns["CK_InfoFromName"].Hidden = false;

            dsTemp = m_bllCK_IntentionDegreeTab.GetList("");

            this.ultraDropDownIntentionDegree.DataSource = dsTemp.Tables[0];
            this.ultraDropDownIntentionDegree.DisplayMember = "CK_IntentionDegreeName";
            this.ultraDropDownIntentionDegree.ValueMember = "CK_IntentionDegreeTabID";
            this.ultraDropDownIntentionDegree.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownIntentionDegree.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownIntentionDegree.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownIntentionDegree.DisplayLayout.Bands[0].Columns["CK_IntentionDegreeName"].Hidden = false;

            dsTemp = m_bllT_ACL_User.GetList("");

            this.ultraDropDownT_ACL_User.DataSource = dsTemp.Tables[0];
            this.ultraDropDownT_ACL_User.DisplayMember = "Name";
            this.ultraDropDownT_ACL_User.ValueMember = "ID";
            this.ultraDropDownT_ACL_User.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownT_ACL_User.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownT_ACL_User.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownT_ACL_User.DisplayLayout.Bands[0].Columns["Name"].Hidden = false;


            //DataSet ds = m_bllCK_StudentRefer.GetList(strWhere);
            foreach (string strTemp in m_dicColName2AliasName.Keys)
            {
                dt.Columns[strTemp].ColumnName = m_dicColName2AliasName[strTemp];

            }
            this.ultraGrid1.DataSource = dt;

            this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["校区名称"].ValueList = this.ultraDropDownDep;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["信息来源"].ValueList = this.ultraDropDownInfoFrom;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["意向程度"].ValueList = this.ultraDropDownIntentionDegree;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["咨询师"].ValueList = this.ultraDropDownT_ACL_User;
      
        }

        void pager1_PageChanged(object sender, EventArgs e)
        {
            BindData(m_filter);
        }

        void pager1_ExportCurrent(object sender, EventArgs e)
        {
            MessageUtil.ShowTips("导出当前页");
        }

        void pager1_ExportAll(object sender, EventArgs e)
        {
            MessageUtil.ShowTips("导出所有");
        }      
  
        private void Frm_ClassRoom_Load_1(object sender, EventArgs e)
        {
            this.pager1.PageChanged += new WHC.Pager.WinControl.PageChangedEventHandler(pager1_PageChanged);
            this.pager1.ExportCurrent += new WHC.Pager.WinControl.ExportCurrentEventHandler(pager1_ExportCurrent);
            this.pager1.ExportAll += new WHC.Pager.WinControl.ExportAllEventHandler(pager1_ExportAll);

            ClassUltraGridCommonSet.InitUltraWinGridSetting(this.ultraGrid1);
            m_dicColName2AliasName.Add("CK_SchoolTabName", "校区名称");
            m_dicColName2AliasName.Add("CK_InfoFromName", "信息来源");
            m_dicColName2AliasName.Add("CK_IntentionDegreeName", "意向程度");
            m_dicColName2AliasName.Add("Name", "咨询师");
            m_dicColName2AliasName.Add("tName", "录入人");
            m_dicColName2AliasName.Add("referDate", "登记日期");
            m_dicColName2AliasName.Add("stdtName", "学员姓名");

            m_dicColName2AliasName.Add("sex", "性别");
            m_dicColName2AliasName.Add("education", "文化程度");
            m_dicColName2AliasName.Add("currSchool", "所在学校");
            m_dicColName2AliasName.Add("grade", "年级");
            m_dicColName2AliasName.Add("mobile", "本人手机");
            m_dicColName2AliasName.Add("tel", "固定电话");
            m_dicColName2AliasName.Add("linkAddr", "联系地址");
            m_dicColName2AliasName.Add("postcode", "邮编");
            m_dicColName2AliasName.Add("eMail", "电子邮件");
            m_dicColName2AliasName.Add("qqMsn", "QQ/MSN");
            m_dicColName2AliasName.Add("motherName", "家长姓名");
            m_dicColName2AliasName.Add("motherMobile", "家长手机");
            m_dicColName2AliasName.Add("motherTel", "家长固话");
            m_dicColName2AliasName.Add("motherWorkUnit", "家长单位");
            m_dicColName2AliasName.Add("nextRvstDate", "下次联系日期");
            m_dicColName2AliasName.Add("referMemo", "备注");
            m_dicColName2AliasName.Add("birthday", "生日");
            foreach (string strTemp in m_dicColName2AliasName.Keys)
            {
                m_dicColAliasName2Name.Add(m_dicColName2AliasName[strTemp], strTemp);
            }
        }

        private void buttonShowAll_Click_1(object sender, EventArgs e)
        {
            m_filter = "";
            ShowAllRecordInDataGridView(m_filter);
        }
        private void InitColumnWidth()
        {

            foreach (string strTemp in m_dicColName2AliasName.Keys)
            {
                ultraGrid1.DisplayLayout.Bands[0].Columns[m_dicColName2AliasName[strTemp]].Width = Frm_Main.m_nDfuColWidth;

            }
            //ultraGrid1.DisplayLayout.Bands[0].Columns["时段"].Width = 80;
            //ultraGrid1.DisplayLayout.Bands[0].Columns["星期设置"].Width = 90;
            //ultraGrid1.DisplayLayout.Bands[0].Columns["缺省学时"].Width = 50;
            //ultraGrid1.DisplayLayout.Bands[0].Columns["教师课时费标准"].Width = 60;
            //ultraGrid1.DisplayLayout.Bands[0].Columns["是否排除节假日"].Width = 60;


        }
        private void ultraGrid1_InitializeLayout_1(object sender, InitializeLayoutEventArgs e)
        {
            InitColumnWidth();
            ClassUltraGridCommonSet.ultraGrid1_InitializeRowFilter(e);
            ClassUltraGridCommonSet.InitUltraWinGridRowNumSetting(e);
        }

        private void 增加一行ToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            if (!m_bInsertFlag)
            {
                AddNewRow();
                //UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
            }
        }

        private void 删除一行ToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            if (!Frm_Main.CheckPerm(this.Text, "删除"))
            {
                MessageBox.Show("对不起您没有该权限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            int nIndex = m_nDelIndex;
            if (m_nDelIndex >= 0)
            {
                DialogResult dr = MessageBox.Show("确实要删除该记录么!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dr == DialogResult.Cancel)
                {
                    return;
                }

                if (ultraGrid1.ActiveRow != null)
                {

                    ultraGrid1.ActiveRow.Delete(false);
                }
            }
            else
            {
                MessageBox.Show("请选中要删除的记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void ultraGrid2_InitializeLayout(object sender, InitializeLayoutEventArgs e)
        {
            InitColumnWidth();
            ClassUltraGridCommonSet.ultraGrid1_InitializeRowFilter(e);
            ClassUltraGridCommonSet.InitUltraWinGridRowNumSetting(e);
        }

        private void ShowAllMXRecordInDataGridView(string strWhere)
        {
            ultraGrid2.DataSource = null;
            DataSet ds = m_bllCK_StudentReferDetail.GetList(strWhere);

            DataSet dsTemp = m_bllCK_IntentionDegreeTab.GetList("");

            this.ultraDropDownIntentionDegree2.DataSource = dsTemp.Tables[0];
            this.ultraDropDownIntentionDegree2.DisplayMember = "CK_IntentionDegreeName";
            this.ultraDropDownIntentionDegree2.ValueMember = "CK_IntentionDegreeTabID";
            this.ultraDropDownIntentionDegree2.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownIntentionDegree2.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownIntentionDegree2.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownIntentionDegree2.DisplayLayout.Bands[0].Columns["CK_IntentionDegreeName"].Hidden = false;

            dsTemp = m_bllT_ACL_User.GetList("");

            this.ultraDropDownPerson.DataSource = dsTemp.Tables[0];
            this.ultraDropDownPerson.DisplayMember = "Name";
            this.ultraDropDownPerson.ValueMember = "ID";
            this.ultraDropDownPerson.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownPerson.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownPerson.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownPerson.DisplayLayout.Bands[0].Columns["Name"].Hidden = false;


            dsTemp = m_bllCK_ClassTab.GetList("");

            this.ultraDropDownClass.DataSource = dsTemp.Tables[0];
            this.ultraDropDownClass.DisplayMember = "CK_className";
            this.ultraDropDownClass.ValueMember = "CK_ClassTabID";
            this.ultraDropDownClass.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownClass.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownClass.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownClass.DisplayLayout.Bands[0].Columns["CK_className"].Hidden = false;

            dsTemp = m_bllCK_ConsultWayTab.GetList("");

            this.ultraDropDownConsultWay.DataSource = dsTemp.Tables[0];
            this.ultraDropDownConsultWay.DisplayMember = "CK_ConsultWayName";
            this.ultraDropDownConsultWay.ValueMember = "CK_ConsultWayTabID";
            this.ultraDropDownConsultWay.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownConsultWay.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownConsultWay.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownConsultWay.DisplayLayout.Bands[0].Columns["CK_ConsultWayName"].Hidden = false;

            ultraGrid2.DataSource = ds.Tables[0];
            this.ultraGrid2.DisplayLayout.Bands[0].Columns["意向班级"].ValueList = this.ultraDropDownClass;
            this.ultraGrid2.DisplayLayout.Bands[0].Columns["咨询方式"].ValueList = this.ultraDropDownConsultWay;
            this.ultraGrid2.DisplayLayout.Bands[0].Columns["意向程度"].ValueList = this.ultraDropDownIntentionDegree2;
            this.ultraGrid2.DisplayLayout.Bands[0].Columns["接待人"].ValueList = this.ultraDropDownPerson;
            ultraGrid2.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            ultraGrid2.DisplayLayout.Bands[0].Columns[1].Hidden = true;

        }
        private void AddNewRowultraGrid2()
        {
            if (Frm_Main.CheckPerm(this.Text, "增加"))
            {
                UltraGridRow row = this.ultraGrid2.DisplayLayout.Bands[0].AddNew();
            }
            else
            {
                MessageBox.Show("对不起您没有该权限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }
        private void ultraGrid2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter && e.Modifiers == Keys.Control)
            {

                if (!m_bInsertFlag)
                {
                    AddNewRowultraGrid2();
                    //UltraGridRow row = this.ultraGrid2.DisplayLayout.Bands[0].AddNew();
                    //  row.Cells[2] = DateTime.Parse("1900-01-01");
                }
            }
            switch (e.KeyCode)
            {

                case Keys.Up:
                    {
                        string strTemp = this.ultraGrid2.ActiveCell.Column.Header.Caption;

                        int nColumnIndex = this.ultraGrid2.ActiveCell.Column.Index;
                        int nIndex = ultraGrid2.ActiveRow.Index;
                        if (nIndex > 0)
                            nIndex--;
                        this.ultraGrid2.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid2.PerformAction(UltraGridAction.AboveCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid2.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid2.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid2.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid2.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Down:
                    {
                        string strTemp = this.ultraGrid2.ActiveCell.Column.Header.Caption;

                        int nColumnIndex = this.ultraGrid2.ActiveCell.Column.Index;
                        int nIndex = ultraGrid2.ActiveRow.Index;
                        if (nIndex < ultraGrid2.Rows.Count - 1)
                            nIndex++;
                        this.ultraGrid2.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid2.PerformAction(UltraGridAction.BelowCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid2.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid2.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid2.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid2.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Right:
                    this.ultraGrid2.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid2.PerformAction(UltraGridAction.NextCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid2.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
                case Keys.Left:
                    this.ultraGrid2.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid2.PerformAction(UltraGridAction.PrevCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid2.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
            }
        }

        private void ultraGrid2_BeforeRowsDeleted(object sender, BeforeRowsDeletedEventArgs e)
        {
            e.DisplayPromptMsg = false;
            if (!m_bInsertFlag2)
            {
                int nSelectFinRecvMoneyDetailTab_NewID = Convert.ToInt32(ultraGrid2.ActiveRow.Cells[0].Value.ToString(), 10);
                TrainingDB.Model.CK_StudentReferDetail modelCK_StudentReferDetailOld = m_bllCK_StudentReferDetail.GetModel(nSelectFinRecvMoneyDetailTab_NewID);

                if (modelCK_StudentReferDetailOld == null)
                {
                    MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (MessageBox.Show("确实要删除该条记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    try
                    {

                        m_bllCK_StudentReferDetail.Delete(nSelectFinRecvMoneyDetailTab_NewID);



                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        e.Cancel = true;
                    }
                }
                else
                {
                    e.Cancel = true;
                }
            }
            else
            {
                MessageBox.Show("插入未完成，不能删除记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;
            }
        }

        private void ultraGrid2_BeforeRowUpdate(object sender, CancelableRowEventArgs e)
        {
            try
            {
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid2.Rows[e.Row.Index];

                if (m_bInsertFlag)
                {
                    ultraGrid2.Rows[e.Row.Index].Cells[2].Activation = Activation.ActivateOnly;
                    m_bInsertFlag = false;
                    if (!AddGoodsDetail2(e.Row.Index))
                        e.Cancel = true;
                }
                else//修改
                {

                    ModifyGoodsDetail2(e.Row.Index);

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;
            }
        }

        private void ultraGrid2_AfterRowInsert(object sender, RowEventArgs e)
        {
            ultraGrid2.Rows[e.Row.Index].Cells[1].IgnoreRowColActivation = true;
            ultraGrid2.Rows[e.Row.Index].Cells[1].Activation = Activation.AllowEdit;
            ultraGrid2.Rows[e.Row.Index].Cells[1].Activate();
            ultraGrid2.PerformAction(UltraGridAction.EnterEditMode);
            m_bInsertFlag2 = true;
            InitNewAddRowValue2(e.Row.Index);
        }

        private void ultraGrid2_AfterCellActivate(object sender, EventArgs e)
        {
            int iIndex = this.ultraGrid2.ActiveCell.Row.Index;
            if (iIndex < 0)
                return;
            m_nDelIndex2 = ultraGrid2.ActiveRow.Index;
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (!m_bInsertFlag2)
            {
                TrainingDB.Model.CK_StudentRefer modelCK_StudentRefer = m_bllCK_StudentRefer.GetModel(m_nStudentReferID);
                if (modelCK_StudentRefer == null)
                {
                    MessageBox.Show("咨询登记记录没有选中，所以无法增加学员跟单信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                else
                {
                    AddNewRowultraGrid2();
                    //UltraGridRow row = this.ultraGrid2.DisplayLayout.Bands[0].AddNew();
                }
          
            }
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            if (!Frm_Main.CheckPerm(this.Text, "删除"))
            {
                MessageBox.Show("对不起您没有该权限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            int nIndex = m_nDelIndex2;
            if (m_nDelIndex2 >= 0)
            {
                DialogResult dr = MessageBox.Show("确实要删除该记录么!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dr == DialogResult.Cancel)
                {
                    return;
                }

                if (ultraGrid2.ActiveRow != null)
                {

                    ultraGrid2.ActiveRow.Delete(false);
                }
            }
            else
            {
                MessageBox.Show("请选中要删除的记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void InitNewAddRowValue2(int nIndex)
        {
            UltraGridRow CurrentUGR = ultraGrid2.Rows[nIndex];

            CurrentUGR.Cells["咨询方式"].Value = 1;
            CurrentUGR.Cells["意向程度"].Value = 1;
            CurrentUGR.Cells["接待人"].Value = 1;
            CurrentUGR.Cells["意向班级"].Value = 1;
            CurrentUGR.Cells["咨询日期"].Value = System.DateTime.Now.Date;
            CurrentUGR.Cells["备注"].Value = "";

            if (m_bInsertFlag2)
            {
                ultraGrid2.Rows[nIndex].Cells[0].Activation = Activation.ActivateOnly;
                m_bInsertFlag2 = false;
                AddGoodsDetail2(nIndex);

            }

        }
        private bool AddGoodsDetail2(int nRowIndex)
        {

            try
            {
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid2.Rows[nRowIndex];



                TrainingDB.Model.CK_StudentReferDetail modelCK_StudentReferDetail = new TrainingDB.Model.CK_StudentReferDetail();

                modelCK_StudentReferDetail.CK_ConsultPersonID = Convert.ToInt32(CurrentUGR.Cells["接待人"].Value.ToString());
                modelCK_StudentReferDetail.CK_ConsultWayTabID = Convert.ToInt32(CurrentUGR.Cells["咨询方式"].Value.ToString());
                modelCK_StudentReferDetail.CK_ClassTabID = Convert.ToInt32(CurrentUGR.Cells["意向班级"].Value.ToString());
                modelCK_StudentReferDetail.CK_IntentionDegreeTabID = Convert.ToInt32(CurrentUGR.Cells["意向程度"].Value.ToString());
                modelCK_StudentReferDetail.CK_StudentReferID = m_nStudentReferID;
                modelCK_StudentReferDetail.CK_DetailDate = (DateTime)CurrentUGR.Cells["咨询日期"].Value;
                modelCK_StudentReferDetail.CK_DetailNote = CurrentUGR.Cells["备注"].Value.ToString();
       

                int nId = m_bllCK_StudentReferDetail.Add(modelCK_StudentReferDetail);
                ShowAllMXRecordInDataGridView("CK_StudentReferDetailid = '" + nId.ToString() + "'");
                //          MessageBox.Show("添加教室成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }

        private bool ModifyGoodsDetail2(int nRowIndex)
        {

            try
            {
                if (!Frm_Main.CheckPerm(this.Text, "修改"))
                {
                    MessageBox.Show("对不起您没有该权限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid2.Rows[nRowIndex];
                int nSelectFinRecvMoneyDetailTab_NewID = Convert.ToInt32(CurrentUGR.Cells[0].Value.ToString(), 10);
                TrainingDB.Model.CK_StudentReferDetail modelCK_StudentReferDetail = m_bllCK_StudentReferDetail.GetModel(nSelectFinRecvMoneyDetailTab_NewID);


                modelCK_StudentReferDetail.CK_DetailDate = (DateTime)CurrentUGR.Cells["咨询日期"].Value;
                modelCK_StudentReferDetail.CK_DetailNote = CurrentUGR.Cells["备注"].Value.ToString();


                string strBGH = CurrentUGR.Cells["意向班级"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_StudentReferDetail.CK_ClassTabID = Convert.ToInt32(CurrentUGR.Cells["意向班级"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_ClassTab.GetList("CK_ClassName = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_StudentReferDetail.CK_ClassTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_ClassTabID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["咨询方式"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_StudentReferDetail.CK_ConsultWayTabID = Convert.ToInt32(CurrentUGR.Cells["咨询方式"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_ConsultWayTab.GetList("CK_ConsultWayName = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_StudentReferDetail.CK_ConsultWayTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_ConsultWayTabID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["接待人"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_StudentReferDetail.CK_ConsultPersonID = Convert.ToInt32(CurrentUGR.Cells["接待人"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllT_ACL_User.GetList("Name = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_StudentReferDetail.CK_ConsultPersonID = Convert.ToInt32(ds.Tables[0].Rows[0]["ID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["意向程度"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_StudentReferDetail.CK_IntentionDegreeTabID = Convert.ToInt32(CurrentUGR.Cells["意向程度"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_IntentionDegreeTab.GetList("CK_IntentionDegreeName = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_StudentReferDetail.CK_IntentionDegreeTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_IntentionDegreeTabID"].ToString(), 10);
                    }
                }

                m_bllCK_StudentReferDetail.Update(modelCK_StudentReferDetail);

                // MessageBox.Show("修改教室成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }



        private void 转为正式学员ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            int nSelectFinRecvMoneyDetailTab_NewID = Convert.ToInt32(ultraGrid1.ActiveRow.Cells[0].Value.ToString(), 10);
            TrainingDB.Model.CK_StudentRefer modelCK_StudentReferOld = m_bllCK_StudentRefer.GetModel(nSelectFinRecvMoneyDetailTab_NewID);


            TrainingDB.Model.CK_StudentInfo modelCK_StudentInfo = new TrainingDB.Model.CK_StudentInfo();

            modelCK_StudentInfo.CK_SchoolTabID = modelCK_StudentReferOld.CK_SchoolTabID;
            modelCK_StudentInfo.CK_OperUserID = Frm_Main.m_nLoginUserId;
            modelCK_StudentInfo.CK_InfoFromTabID = modelCK_StudentReferOld.CK_InfoFromTabID;
            modelCK_StudentInfo.CK_ConsultTeacherTabID = modelCK_StudentReferOld.CK_ConsultPersonID;
            modelCK_StudentInfo.CK_StudentReferID = nSelectFinRecvMoneyDetailTab_NewID;


            modelCK_StudentInfo.stdtName = modelCK_StudentReferOld.stdtName;
            modelCK_StudentInfo.sex = modelCK_StudentReferOld.sex;
            modelCK_StudentInfo.education = modelCK_StudentReferOld.education;
            modelCK_StudentInfo.currSchool = modelCK_StudentReferOld.currSchool;
            modelCK_StudentInfo.grade = modelCK_StudentReferOld.grade;

            modelCK_StudentInfo.mobile = modelCK_StudentReferOld.mobile;
            modelCK_StudentInfo.tel = modelCK_StudentReferOld.tel;
            modelCK_StudentInfo.linkAddr = modelCK_StudentReferOld.linkAddr;
            modelCK_StudentInfo.postcode = modelCK_StudentReferOld.postcode;
            modelCK_StudentInfo.eMail = modelCK_StudentReferOld.eMail;
            modelCK_StudentInfo.qqMsn = modelCK_StudentReferOld.qqMsn;
            modelCK_StudentInfo.motherName = modelCK_StudentReferOld.motherName;
            modelCK_StudentInfo.motherMobile = modelCK_StudentReferOld.motherMobile;
            modelCK_StudentInfo.motherTel = modelCK_StudentReferOld.motherTel;
            modelCK_StudentInfo.motherWorkUnit = modelCK_StudentReferOld.motherWorkUnit;
            modelCK_StudentInfo.stdtMemo = modelCK_StudentReferOld.stdtName;
            modelCK_StudentInfo.enterDate = System.DateTime.Now.Date;
            modelCK_StudentInfo.birthday = modelCK_StudentReferOld.birthday;
            modelCK_StudentInfo.fpNO = "";
            modelCK_StudentInfo.cardNO = "";

            modelCK_StudentInfo.stdtPicPath = "";
            modelCK_StudentInfo.stdtPicFExt = "";
            modelCK_StudentInfo.pyHelperCode = "";
            modelCK_StudentInfo.isAtSchl = true;

            int nId = m_bllCK_StudentInfo.Add(modelCK_StudentInfo);
            Frm_Main.GetMainForm().ShowContent("报名登记");
        }

      

    }
}
